﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;

namespace logic
{
    public class priceStructure
    {
        public static void insert(PriceStructureEntity ps)
        {
            PriceStructure.insert(ps);
        }

        public static void insertByProduct(PriceStructureEntity ps)
        {
            PriceStructure.insertByProduct(ps);
        }

        public static void updateByProduct(PriceStructureEntity ps)
        {
            PriceStructure.updateByProduct(ps);
        }

        public static void deleteByCompany(int companyId)
        {
            PriceStructure.deleteByCompany(companyId);
        }
        public static DataSet listByCompanyAndCategory(string where,string orderBy,int pageSize,int pageIndex)
        {
            return DbHelper.ExecuteDataSetPageSize("*", "vw_Company_AutoPercentList", where, "sId", orderBy, pageSize, pageIndex);
        }

        /// <summary>
        /// 企业价格体系初始化
        /// </summary>
        /// <param name="adminId"></param>
        /// <param name="companyId"></param>
        /// <param name="categoryAutoPercentMap">类别、加价比例映射表</param>
        public static void Init(int adminId,int companyId, string categoryAutoPercentMap)
        {
            PriceStructure.Init(adminId,companyId, categoryAutoPercentMap);
        }

        public static DataSet select(string where,string orderBy,int pageSize, int pageIndex)
        {
            return DbHelper.ExecuteDataSetPageSize("*", "[dbo].[vw_PriceStructure_list]", where, "[sId]", orderBy, pageSize, pageIndex);
        }

        public static void update(int companyId, int productId, decimal productAutoAdd, decimal autoPercent,int adminId)
        {
            PriceStructure.update(companyId,productId,productAutoAdd,autoPercent,adminId);
        }

        public static DataTable getProductAutoAddByProductNameOrProductNo(string Rn,string whereClause,bool enableLike)
        {
            return PriceStructure.getProductAutoAddByProductNameOrProductNo(Rn,whereClause,enableLike);
        }

        public static void updateProductAutoAddBlock(int adminId,int productId,decimal oldProductAutoAdd,decimal productAutoadd, bool isApplyAll)
        {
            PriceStructure.updateProductAutoAddBlock(adminId, productId,oldProductAutoAdd,productAutoadd, isApplyAll);
        }

        public static void InsertProductAutoAdd(string nature, int companyId, int adminId)
        {
            PriceStructure.InsertProductAutoAdd(nature,companyId,adminId);
        }
        public static DataSet listWithProductAutoAdd(string where, string orderBy, int pageSize, int pageIndex)
        {
            return DbHelper.ExecuteDataSetPageSize("*", "[dbo].[vw_PriceStructure_listWithProductAutoAdd]", where, "[productId]", orderBy, pageSize, pageIndex);
        }

        /// <summary>
        /// 根据采购档次以及商品ID修改系统加价体系
        /// </summary>
        /// <param name="bn">采购档次：餐饮、食堂、酒店</param>
        /// <param name="productId">商品ID</param>
        /// <param name="sysAutoAdd">新的系统加价</param>
        /// <param name="adminId">操作员ID</param>
        public static void updateByProductIdAndBN(string bn, int productId, decimal sysAutoAdd, int adminId)
        {
            PriceStructure.updateByProductIdAndBN(bn, productId, sysAutoAdd, adminId);
        }
    }
}
